package com.audaque.springboot.foshanupload.jpa.base.entity;


import com.audaque.springboot.foshanupload.jpa.config.UserIDAuditorBean;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
/**
 * 1.标注为@MappedSuperclass的类将不是一个完整的实体类，他将不会映射到数据库表，但是他的属性都将映射到其子类的数据库字段中。
 * 2.标注为@MappedSuperclass的类不能再标注@Entity或@Table注解，也无需实现序列化接口。
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity  extends UserIDAuditorBean implements Serializable {
    private static final long serialVersionUID = -5986017902421307884L;

    /** 自增主键 */

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID",nullable = false)
    @Basic //指定属于我们数据表的一个列，相反的@Transient，表示该列不属于数据表
    @Id
    @JsonSerialize(using = ToStringSerializer.class) // 解决Long型长度超过17位后前端精度不够的问题
//    @GeneratedValue(strategy= GenerationType.AUTO)
//    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "menuSeq")
//    @SequenceGenerator(name = "menuSeq", initialValue = 1, allocationSize = 1, sequenceName = "MENU_SEQUENCE")
    private Long id;

    @JsonSerialize(using = ToStringSerializer.class)
    @JsonIgnore
    @CreatedBy
    @Column(name = "CREATE_USER_ID")
    private Long createUserId;

    @JsonIgnore
    @CreatedDate
    @Column(name = "CREATE_TIME")
    private Date createTime;

    @JsonSerialize(using = ToStringSerializer.class)
    @JsonIgnore
    @LastModifiedBy
    @Column(name = "UPDATE_USER_ID")
    private Long updateUserId;

    @JsonIgnore
    @LastModifiedDate
    @Column(name = "UPDATE_TIME")
    private Date updateTime;

    @JsonSerialize(using = ToStringSerializer.class)
    @JsonIgnore
    @Column(name = "DEL_USER_ID")
    private Long delUserId;

    @JsonIgnore
    @Column(name = "DEL_TIME")
    private Date delTime;

    /**
     * 业务都统一
     * 0 是有效  1 是无效
     */
    @JsonIgnore
    @Column(name = "IS_DEL", length = 1)
    private Integer isDel = 0;

    @JsonIgnore
    @Column(name = "ATTR1")
    private String attr1;

    @JsonIgnore
    @Column(name = "ATTR2")
    private String attr2;

    @JsonIgnore
    @Column(name = "ATTR3")
    private String attr3;


}
